﻿@page "/log"
@page "/log/{TaskId}"
@inject I18n I18n
@inject NavigationManager NavigationManager

<PageTitle>@I18n.Log("Log")</PageTitle>

<LogPanel PageMode=true TaskId="@TaskId" StartTime="ToDateTime(StartTime)" EndTime="ToDateTime(EndTime)" Service="@Service" Keyword="@Keyword" />

@code {

    /// <summary>
    /// scheduler job taskId
    /// </summary>
    [Parameter]
    public string TaskId { get; set; }

    [Parameter]
    [SupplyParameterFromQuery]
    public string StartTime { get; set; }

    [Parameter]
    [SupplyParameterFromQuery]
    public string EndTime { get; set; }

    [Parameter]
    [SupplyParameterFromQuery]
    public string Service { get; set; }

    [Parameter]
    [SupplyParameterFromQuery]
    public string Keyword { get; set; }

    DateTime ToDateTime(string? str)
    {
        if (!string.IsNullOrEmpty(str) && DateTime.TryParse(str, out var time))
            return time;
        return DateTime.MinValue;
    }

    protected override void OnAfterRender(bool firstRender)
    {
        if (!firstRender)
        {
            NavigationManager.NavigateTo("/log", true);
            return;
        }
        base.OnAfterRender(firstRender);
    }
}